package com.cryptoneedle.garden.service.util;

import com.cryptoneedle.garden.constant.ConfigConstant;
import com.cryptoneedle.garden.entity.garden.config.ConfigProperty;
import com.cryptoneedle.garden.repository.garden.config.ConfigPropertyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <p>description:  </p>
 *
 * @author CryptoNeedle
 * @date 2025-11-05
 */
@Component
public class ConfigUtil {

    @Autowired
    private ConfigPropertyRepository configPropertyRepository;

    public String ods() {
        return getValue(ConfigConstant.DORIS_DATABASE_ODS);
    }

    public String dwd() {
        return getValue(ConfigConstant.DORIS_DATABASE_DWD);
    }

    public String dws() {
        return getValue(ConfigConstant.DORIS_DATABASE_DWS);
    }

    public String ads() {
        return getValue(ConfigConstant.DORIS_DATABASE_ADS);
    }

    public String dim() {
        return getValue(ConfigConstant.DORIS_DATABASE_DIM);
    }

    public String mapping() {
        return getValue(ConfigConstant.DORIS_DATABASE_MAPPING);
    }


    public String dsHost() {
        return getValue(ConfigConstant.DOLPHIN_SCHEDULER_HOST);
    }

    public String dsPort() {
        return getValue(ConfigConstant.DOLPHIN_SCHEDULER_PORT);
    }

    public String dsUrl() {
        return "https://" + dsHost() + ":" + dsPort() + "/dolphinscheduler";
    }

    public String dsToken() {
        return getValue(ConfigConstant.DOLPHIN_SCHEDULER_TOKEN);
    }

    public String dsProjectName() {
        return getValue(ConfigConstant.DOLPHIN_SCHEDULER_PROJECT_NAME);
    }

    public String getValue(String name) {
        String value = configPropertyRepository.value(name);
        if (value == null) {
            throw new RuntimeException("Doris Config 未配置：%s".formatted(name));
        }
        return value;
    }

    public ConfigProperty get(String name) {
        ConfigProperty configProperty = configPropertyRepository.property(name);
        if (configProperty == null) {
            throw new RuntimeException("Doris Config 未配置：%s".formatted(name));
        }
        return configProperty;
    }
}